/**
 * Created by guosc on 2016/10/25 0025.
 */
define(["angular",
    "framework/utils/JSONPrettyFormat",
    'framework/dataGrid/DataGridModule',
    'framework/pagination/GillionPaginationModule',
    'framework/msg/GillionMsgModule'
],function (angular, JSONPrettyFormat) {
    var CreateRuleModule = angular.module("CopyRuleModule", [
        'DataGridModule',
        'GillionPaginationModule',
        'GillionMsgModule']);

    CreateRuleModule.controller("CopyRuleController", function ($scope,Resource,$location,GillionMsg,GillionMsgService,$http) {
        var app = Resource("/grule-manager/rule/copy");
        $scope.params=GillionMsgService.getInputData();

        $http.get('/grule-manager/rulePackage/getRulePackages/' +$scope.params.projectId).success(function (resp) {
            if(resp.data=="reload"){
                location.reload();
            }else {
                $scope.packages = resp.data;
            }
        });

        $scope.setAss=function(id){
            $http({
                url:"/grule-manager/ruleAssembly/copy",
                method:"GET",
                params:{
                    id:id
                }
            }).success(function(resp){
                $scope.ass = resp;
            });
        }




        $scope.confirm=function(){
           $scope.rule.id = $scope.params.ruleId;
            if($scope.rule.ruleAssemblyId==undefined){
               //提示
            }
            app.create($scope.rule,function(response){
                if (response.success) {
                    GillionMsgService.setOutputData(response);
                    GillionMsgService.close();
                } else {
                    GillionMsg.alert("提示", "规则复制失败");
                }
            })
        };
        $scope.cancel=function(){
            GillionMsgService.close();
        }

    });

});